package com.mayuhao.permissionmanage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mayuhao.permissionmanage.entity.CssMenu;
import com.mayuhao.permissionmanage.entity.CssRole;
import com.mayuhao.permissionmanage.mapper.CssRoleMenuMapper;
import com.mayuhao.permissionmanage.service.ICssRoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 马宇豪
 * @since 2022-10-28
 */
@Service
public class CssRoleMenuServiceImpl extends ServiceImpl<CssRoleMenuMapper, CssRole> implements ICssRoleMenuService {
    @Resource
    private CssRoleMenuMapper roleMenuMapper;

    /**
     * @return java.util.List<com.mayuhao.permissionmanage.entity.CssRole>
     * @description 请修改方法描述
     * @methodName selectRoleMenu
     * @params [roleId]
     * @paramType [java.lang.Integer]
     * @author 马宇豪
     * @date 2022/10/28 0028 下午 3:16
     * @email 1757442521@qq.com
     **/


    @Transactional
    @Override
    public List<CssMenu> selectMenu() {
        return roleMenuMapper.selectMenu();
    }

    /**
     * @return boolean
     * @description 请修改方法描述
     * @methodName roleMenu
     * @params [roleId, menuIds]
     * @paramType [java.lang.String, java.util.List<java.lang.Integer>]
     * @author 马宇豪
     * @date 2022/10/28 0028 下午 4:22
     * @email 1757442521@qq.com
     **/
    @Override
    public boolean backRoleMenu(String roleId, List<String> menuIds) {
        //先删除当前角色绑定的权限
        roleMenuMapper.deleteroleMenu(roleId);
        //再插入当前角色选择的权限
        for (String menuId : menuIds) {
            roleMenuMapper.insertroleMenu(roleId, menuId);
        }
        return true;

    }

    /**
     * @return java.util.List<java.lang.Integer>
     * @description 请修改方法描述
     * @methodName boundRoleMenu
     * @params [roleId]
     * @paramType [java.lang.Integer]
     * @author 马宇豪
     * @date 2022/10/28 0028 下午 5:59
     * @email 1757442521@qq.com
     **/
    @Override
    public List<String> boundRoleMenu(String roleId) {
        return roleMenuMapper.boundRoleMenu(roleId);
    }
}
